package com.aw.baselib.widgets

import android.app.Dialog
import android.content.Context
import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.TextView
import com.aw.baselib.R
import com.aw.baselib.util.DensityUtil

/**
 * @author : hzw
 * @date : 2021/12/7
 */
class LoadingDialog(context: Context) : Dialog(context, R.style.LoadingDialog) {
    private val tvMsg: TextView

    init {
        setCanceledOnTouchOutside(false)
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null, false)
        tvMsg = view.findViewById(R.id.tv_msg)
        setContentView(view)
        val window = window
        val lp = window!!.attributes
        lp.width = DensityUtil.dip2px(context, 150f)
        lp.height = DensityUtil.dip2px(context, 110f)
        lp.gravity = Gravity.CENTER
        window.attributes = lp
    }

    /**
     * 设置等待提示信息
     */
    fun setLoadingMsg(msg: String?) {
        if (TextUtils.isEmpty(msg)) {
            return
        }
        tvMsg.text = msg
    }
}